home *** CD-ROM | disk | FTP | other *** search
- package netscape.applet;
-
- import java.net.URL;
- import java.util.Vector;
- import netscape.application.Application;
- import netscape.application.CommandEvent;
- import netscape.application.Event;
- import netscape.application.EventLoop;
- import netscape.util.Enumeration;
- import netscape.util.Hashtable;
- import netscape.util.InconsistencyException;
-
- final class Task implements Runnable {
- static Hashtable taskByName;
- String _taskName;
- TaskThreadGroup group;
- Thread thread;
- URL _codebaseURL;
- URL _archiveURL;
- AppletClassLoader _classLoader;
- String _appClassName;
- Application _application;
- EventLoop eventLoop;
- TaskOwner _taskOwner;
- Vector initialEventQueue = new Vector();
- boolean registered;
- boolean running;
- boolean dead;
- boolean runLocked;
-
- public static void destroyAll() {
- Enumeration var0 = getTasks();
-
- while(var0.hasMoreElements()) {
- Task var1 = (Task)var0.nextElement();
- var1.stop();
- }
-
- }
-
- public static Task currentTask() {
- for(ThreadGroup var0 = Thread.currentThread().getThreadGroup(); var0 != null; var0 = var0.getParent()) {
- if (var0 instanceof TaskThreadGroup) {
- return ((TaskThreadGroup)var0).task();
- }
- }
-
- return null;
- }
-
- public static synchronized Task taskNamed(URL var0, String var1) {
- return taskByName == null ? null : (Task)taskByName.get(new TaskID(var0, var1));
- }
-
- static synchronized void registerTask(Task var0) {
- if (taskByName == null) {
- taskByName = new Hashtable();
- }
-
- if (!var0.registered) {
- taskByName.put(new TaskID(var0.codebaseURL(), var0.taskName()), var0);
- var0.registered = true;
- }
- }
-
- static synchronized void unregisterTask(Task var0) {
- if (taskByName != null && var0.registered) {
- taskByName.remove(new TaskID(var0.codebaseURL(), var0.taskName()));
- var0.registered = false;
- }
- }
-
- public static synchronized Enumeration getTasks() {
- if (taskByName == null) {
- taskByName = new Hashtable();
- }
-
- return ((Hashtable)taskByName.clone()).elements();
- }
-
- public Task(String var1, String var2, URL var3, URL var4, TaskOwner var5) {
- this._taskName = var1;
- this._appClassName = var2;
- this._codebaseURL = var3;
- this._archiveURL = var4;
- this._taskOwner = var5;
- SecurityManager.enablePrivilege("UniversalThreadAccess");
- SecurityManager.enablePrivilege("UniversalThreadGroupAccess");
- this.group = new TaskThreadGroup(var1, this);
- this.thread = new Thread(this.group, this);
- SecurityManager.revertPrivilege();
- registerTask(this);
- }
-
- public String taskName() {
- return this._taskName;
- }
-
- public URL codebaseURL() {
- return this._codebaseURL;
- }
-
- public URL archiveURL() {
- return this._archiveURL;
- }
-
- public TaskOwner taskOwner() {
- return this._taskOwner;
- }
-
- public ThreadGroup threadGroup() {
- return this.group;
- }
-
- public Application application() {
- return this._application;
- }
-
- public ClassLoader classLoader() {
- if (this._classLoader != null) {
- return this._classLoader;
- } else if (this._codebaseURL == null) {
- return null;
- } else {
- this._classLoader = new AppletClassLoader((MozillaAppletContext)null, this._codebaseURL, this._archiveURL);
- return this._classLoader;
- }
- }
-
- public synchronized boolean isRunning() {
- return this.running;
- }
-
- public synchronized boolean isDead() {
- return this.dead;
- }
-
- public void run() {
- synchronized(this){}
-
- try {
- if (this.runLocked) {
- throw new InconsistencyException("Do not run a Task more than once.");
- }
-
- this.runLocked = true;
- } catch (Throwable var30) {
- throw var30;
- }
-
- try {
- this.prepareToRun();
- synchronized(this){}
-
- try {
- this.running = true;
- this.moveEvents();
- this.notifyAll();
- } catch (Throwable var28) {
- throw var28;
- }
-
- this.didStartRunning();
- this._application.run();
- } finally {
- synchronized(this){}
-
- try {
- this.running = false;
- this.dead = true;
- this.notifyAll();
- } catch (Throwable var27) {
- throw var27;
- }
-
- unregisterTask(this);
- this.didStopRunning();
- }
-
- this.stop();
- }
-
- private void prepareToRun() {
- Class var1;
- try {
- var1 = this.loadClass(this._appClassName);
- } catch (ClassNotFoundException var6) {
- ((Throwable)var6).printStackTrace(System.err);
- throw new Error("I'm going under!!!");
- }
-
- Object var2;
- try {
- var2 = var1.newInstance();
- } catch (InstantiationException var4) {
- ((Throwable)var4).printStackTrace(System.err);
- throw new Error("I'm going under!!!");
- } catch (IllegalAccessException var5) {
- ((Throwable)var5).printStackTrace(System.err);
- throw new Error("I'm going under!!!");
- }
-
- this._application = (Application)var2;
- this.eventLoop = this._application.eventLoop();
- if (this._taskOwner != null) {
- this._taskOwner.appDidConstruct(this._application);
- }
-
- }
-
- private void didStartRunning() {
- }
-
- private void didStopRunning() {
- }
-
- public void start() {
- this.thread.start();
- }
-
- public void stop() {
- AppletThreadList var1 = new AppletThreadList(this.group, this);
- MozillaAppletContext.killer.addAppletThread(var1);
- }
-
- public void requestShutdown() {
- if (!this.dead && this._taskOwner != null) {
- this._taskOwner.taskWillShutdown(this);
- }
-
- this._classLoader = null;
- }
-
- private void moveEvents() {
- if (this.initialEventQueue != null) {
- for(int var2 = 0; var2 < this.initialEventQueue.size(); ++var2) {
- CommandEvent var1 = (CommandEvent)this.initialEventQueue.elementAt(var2);
- this.eventLoop.addEvent(var1);
- }
-
- this.initialEventQueue = null;
- }
- }
-
- public synchronized void addEvent(Event var1) {
- if (this.eventLoop != null) {
- if (this.initialEventQueue != null) {
- this.moveEvents();
- }
-
- this.eventLoop.addEvent(var1);
- } else {
- this.initialEventQueue.insertElementAt(var1, this.initialEventQueue.size());
- }
- }
-
- public Class loadClass(String var1) throws ClassNotFoundException {
- AppletClassLoader var2 = (AppletClassLoader)this.classLoader();
- return var2 == null ? Class.forName(var1) : var2.loadClass(var1);
- }
-
- public synchronized void waitUntilRunningOrDead() {
- while(!this.isRunning() && !this.isDead()) {
- try {
- this.wait();
- } catch (InterruptedException var1) {
- }
- }
-
- }
- }
-